import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';

class me_page extends StatefulWidget {
  @override
  MePage createState() => MePage();
}

class MePage extends State<me_page> with SingleTickerProviderStateMixin {
  @override
  Ticker createTicker(onTick) {
    return Ticker(onTick, debugLabel: 'created by $this');
  }

  @override
  Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
        statusBarColor: Colors.transparent,
        statusBarIconBrightness: Brightness.dark));
    return Scaffold(
        body: SafeArea(
            child: CustomScrollView(
      shrinkWrap: true,
      slivers: <Widget>[
        SliverPadding(
          padding: const EdgeInsets.all(0.0),
          sliver: SliverList(
            delegate: SliverChildListDelegate(
              <Widget>[
                Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 10),
                  child: Column(
                    children: [
                      Column(
                        children: [
                          Container(
                            width: double.infinity,
                            child: const Text("我的",
                                style: TextStyle(
                                    fontSize: 18, fontWeight: FontWeight.bold)),
                            alignment: Alignment.center,
                          ),
                          InkWell(
                            onTap: () {
                              dialog_input(context);
                            },
                            child: Padding(
                              padding: const EdgeInsets.all(5),
                              child: Container(
                                width: double.infinity,
                                child: const Text("完成"),
                                alignment: Alignment.centerRight,
                              ),
                            ),
                          ),
                        ],
                      ),
                      const Divider(
                        thickness: 1,
                      ),
                      Padding(
                        padding: const EdgeInsets.symmetric(horizontal: 20),
                        child: Column(
                          children: [
                            getItem("姓名", "谢乙田"),
                            getDesc("为保证测算的准确度，请填写真实信息。"),
                            getItem("年龄", "20"),
                            getItem("性别", "男"),
                          ],
                        ),
                      ),
                      const Divider(thickness: 1, indent: 50),
                      Padding(
                        padding: const EdgeInsets.symmetric(horizontal: 20),
                        child: Column(
                          children: [
                            getItem("生日", "10.18"),
                            getItem("星座", "天秤座"),
                          ],
                        ),
                      ),
                      const Divider(thickness: 1, indent: 50),
                      Padding(
                        padding: const EdgeInsets.symmetric(horizontal: 20),
                        child: Column(
                          children: [
                            getItem("生肖", "龙"),
                            getItem("手机号码", "立即绑定"),
                          ],
                        ),
                      ),
                      const Divider(thickness: 1, indent: 50),
                      Padding(
                        padding: const EdgeInsets.symmetric(horizontal: 20),
                        child: Column(
                          children: [
                            getItem("微信账号", "立即绑定"),
                            getDesc(
                                "授权绑定“手机号码”或者“微信账号”之后，可以使用手机号码或微信账号登陆今日运势。"),
                            getItem("我的神兽", "购买记录"),
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ),
      ],
    )));
  }

  getItem(String s, String t) {
    return InkWell(
      onTap: () {
        if (s == "我的神兽") {
          Navigator.of(context).pushNamed("mypet");
        }
      },
      child: Row(
        children: [
          Text(s),
          Padding(
            padding: const EdgeInsets.symmetric(vertical: 10),
            child: Row(
              children: [
                Text(
                  t,
                  style: const TextStyle(color: Colors.grey, fontSize: 14),
                ),
                const Icon(
                  Icons.chevron_right,
                  color: Colors.grey,
                )
              ],
            ),
          ),
        ],
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
      ),
    );
  }

  getDesc(String s) {
    return SizedBox(
      width: double.infinity,
      child: Padding(
        padding: const EdgeInsets.only(bottom: 20),
        child: Text(s, style: const TextStyle(color: Colors.grey)),
      ),
    );
  }

  Future<void> dialog_input(context) async {
    showCupertinoDialog(
        context: context,
        builder: (context) {
          return CupertinoAlertDialog(
            title: const Text('温馨提示'),
            content: const CupertinoTextField(),
            actions: <Widget>[
              CupertinoDialogAction(
                onPressed: () {
                  Navigator.pop(context);
                },
                child: const Text('取消'),
              ),
              CupertinoDialogAction(
                onPressed: () {
                  Navigator.pop(context);
                },
                child: const Text('确定'),
              ),
            ],
          );
        });
  }
}
